package com.lombardrisk.component
{
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.system.Capabilities;
	
	import mx.containers.Panel;
	import mx.controls.Button;
	import mx.controls.Image;
	import mx.controls.Label;
	import mx.controls.Text;
	import mx.controls.TextInput;
	import mx.effects.Resize;
	import mx.effects.easing.Bounce;
	
	public class MyPanel extends Panel
	{
		private var _restoreImg:Image = new Image();
		private var _maxImg : Image = new Image();
		
		public var _errorLabel: Text = new Text();
		
		private var restoreHeight:Number;
		
		public  function set errorLabel(text:String){
			_errorLabel.toolTip = text;
			this._errorLabel.text = text;
		} 
		
		private var eff:Resize = new Resize();
		
		public function MyPanel()
		{
			super();
			
			/*         this.titleBar.buttonMode=true;
			this.titleBar.addEventListener(MouseEvent.CLICK,resizeHandler); */
			
			eff.heightTo=this.maxHeight;
			eff.easingFunction=Bounce.easeOut;
		}
		
		protected override function createChildren(): void {
			super.createChildren();
			restoreHeight = this.height;
			_errorLabel.height=25;
			_errorLabel.width=Capabilities.screenResolutionX*0.8;	
			_errorLabel.setStyle("color",0xFF0000);
			_errorLabel.setStyle("fontFamily","YaHei Consolas Hybrid");
			this.rawChildren.addChild(_errorLabel);
			
			_maxImg.height=17;
			_maxImg.width=18;
			_maxImg.toolTip = "Maximize";		
			_maxImg.addEventListener(MouseEvent.CLICK,maximizeHandler);	
			_maxImg.source ="assets/icon/icon_maximize.png";
			this.rawChildren.addChild(_maxImg);
			
			_restoreImg.height=17;
			_restoreImg.width=18;		
			_restoreImg.toolTip = "Restore";
			_restoreImg.source ="assets/icon/icon_restore.png";			
			_restoreImg.enabled = false;	
			_restoreImg.addEventListener(MouseEvent.CLICK,restoreHandler);
			this.rawChildren.addChild(_restoreImg);
			
		}
		
		protected override function layoutChrome(unscaledWidth: Number, unscaledHeight:Number):void {
			super.layoutChrome(unscaledWidth, unscaledHeight);		
			
			_restoreImg.move(this.width-45,6);
			_maxImg.move(this.width-25,6);
			
			_errorLabel.move(100,6);			
		}
		
		private function restoreHandler(evt:MouseEvent):void{
			
			eff.heightTo=restoreHeight;
			eff.duration=1000;
			eff.easingFunction = eff.easingFunction==Bounce.easeOut?Bounce.easeIn:Bounce.easeOut;
			eff.target=this;
			_maxImg.enabled= true;
			_restoreImg.enabled = false;
			eff.play();
			
		}
		
		private function maximizeHandler(evt:MouseEvent):void{
			restoreHeight = this.height;
			eff.heightTo=screen.height;
			eff.duration=1000;
			eff.easingFunction = eff.easingFunction==Bounce.easeOut?Bounce.easeIn:Bounce.easeOut;
			_maxImg.enabled= false;
			_restoreImg.enabled = true;
			eff.target=this;
			eff.play();
		}
	}
}
